import numpy as np
import pandas as pd
from pandas import Series,DataFrame
s = Series([1,4,'ww','tt'])
print(s)
print(s.index)
print(s.values)

#自定义索引
s2 = Series(['wangxing','man',24],index=['name','sex','age'])
print(s2)
print(s2['name'])
#dict定义
sd = {'python': 9000, 'c++': 9001, 'c#': 9000}
s3 = Series(sd)
print(s3)
#索引依然可以自定义。Pandas 的优势在这里体现出来，
# 如果自定义了索引，自定的索引会自动寻找原来的索引，如果一样的，就取原来索引对应的值，这个可以简称为“自动对齐”。
s4 = Series(sd,index=['java','c++','c#'])
print(s4)
#索引重新定义
s4.index = ['语文','数学','English']
print(s4)
#DataFrame
#使用 dict 定义
data = {"name":['google','baidu','yahoo'],"marks":[100,200,300],"price":[1,2,3]}
f1 = DataFrame(data)
print(f1)
#自定义DataFrame的columns和index
f3 = DataFrame(data,columns=['marks','name','price'],index=['a','b','c'])
print(f3)
#字典套字典定义
newdata = {'lang':{'first':'python','second':'java'},'price':{'first':5000,'second':2000}}
f4 = DataFrame(newdata)
print(f4)
#DataFrame对象每一列都是Series对象
#对同一列赋值
f4['price']=10000
print(f4)
#定义Series来赋值
ssex = Series(['男','女'],index=['first','second'])
f4['price']=ssex
print(f4)
f4['price']['second'] = 1000
print(f4)